import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * Date: 2023-04-25
 * Time: 17:36
 */
public class MyJFrame2 extends JFrame{

    //创建一个按钮对象
    JButton jtb1 = new JButton("点我啊");

    public MyJFrame2() {
        //设置界面的宽高
        this.setSize(603, 680);
        //设置界面的标题
        this.setTitle("拼图单机版 v1.0");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //取消默认的居中放置，只有取消了才会按照XY轴的形式添加组件
        this.setLayout(null);
        // 给按钮设置位置和宽高
        jtb1.setBounds(0,0,100,50);

        // 给按钮添加鼠标事件
        jtb1.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent mouseEvent) {
                System.out.println("点击");
            }

            @Override
            public void mousePressed(MouseEvent mouseEvent) {
                System.out.println("按住不松");
            }

            @Override
            public void mouseReleased(MouseEvent mouseEvent) {
                System.out.println("松开");
            }

            @Override
            public void mouseEntered(MouseEvent mouseEvent) {
                System.out.println("划入");
            }

            @Override
            public void mouseExited(MouseEvent mouseEvent) {
                System.out.println("划出");
            }
        });



        // 将按钮添加到界面当中
        this.getContentPane().add(jtb1);
        // 显示
        this.setVisible(true);
    }

}
